package com.customds.impl;

/*
	Author: Leo
	Creation Date: 4-8-2012
	Creation Time: 1:16 AM
*/

import java.util.*;
import java.sql.*;

public class CocoaMap {
	// Data member declaration
	private static int ROW_NUM = 0;
	private static int TABLE_SIZE;
	
	Map<String, LinkedHashMap<String, ArrayList<String>>> cocoaMap; // Protocol 10 will be my legacy
	Map<String, ArrayList<String>> cocoaSubmap;
	ArrayList<String> cocoaList;
	ArrayList<String> cocoaRow;
	
	String key;
	// String column;
	
	TableDataRetriever tdr;
	ResultSet resultSet;
	
	public CocoaMap() {
		// The Mammoth definition
		cocoaMap = new LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>>();
		cocoaSubmap = new LinkedHashMap<String, ArrayList<String>>();
		cocoaList = new ArrayList<String>();
		cocoaRow = new ArrayList<String>();
		
		key = "";
		// column = "";
		
		tdr = null;
		resultSet = null;
	}
	
	// [MESSAGE] Modification encouraged
	public void initComponents() throws SQLException {
		tdr = new TableDataRetriever();
		cocoaSubmap = tdr.getColumnWithMetaData(resultSet);
		
		TABLE_SIZE = tdr.getTableSize();
		
		// Prepare the Cocoa Map
		cocoaMap.put(key, (LinkedHashMap<String, ArrayList<String>>) cocoaSubmap);
	} // End of method
	
	public ArrayList<String> getCocoaRow(String...columnList) {
		// Refresh the ArrayList before use
		cocoaRow = new ArrayList<String>();
		
		for(String column : columnList) {
			for(Map.Entry<String, ArrayList<String>> entry : cocoaSubmap.entrySet()) {
				if(column.equalsIgnoreCase(entry.getKey())) {
					cocoaRow.add(entry.getValue().get(ROW_NUM));
				}
				
			} // End of inner for-loop
		
		} // End of outer for-loop 
		
		ROW_NUM++;
		
		return cocoaRow;
	} // End of method
	
	public int getTableSize() {
		return TABLE_SIZE;
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	public ResultSet getResultSet() {
		return resultSet;
	}
	
	public void setResultSet(ResultSet resultSet) {
		this.resultSet = resultSet;
	}
	
} // End of class 